package org.strieber.fca.mid3;

import java.util.ArrayList;
import java.util.List;

public class Tree<T> {

	private Node<T> rootElement;
	
	public Tree() {
		
	}
	
	// return the root node of the tree
	public Node<T> getRootElement() {
		return rootElement;
	}
	// set the root element of the tree
	public void setRootElement(Node<T> rootElement) {
		this.rootElement = rootElement;
	}
	// traverse the tree in pre-order style (internal method)
	private void preorder(Node<T> element, List<Node<T>> list) {
		list.add(element);
		for (Node<T> data : element.getChildren()) {
			preorder(data, list);
		}
	}
	// convert this tree in to a list
	public List<Node<T>> toList() {
		List<Node<T>> list = new ArrayList<Node<T>>();
		preorder(rootElement, list);
		return list;
	}
	public String toString() {
		return toList().toString();
	}
}